package com.gotop.common.utils;

import java.text.ParseException;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @program: cem
 * @description:
 * @author: superfish
 * @create: 2020-12-25 13:53
 **/
public class DateUtil {

    public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss";
    public static final String PATTERN_DATE = "yyyy-MM-dd";
    public static final String PATTERN_TIME = "HH:mm:ss";
    public static final ConcurrentDateFormat DATETIME_FORMAT = ConcurrentDateFormat.of("yyyy-MM-dd HH:mm:ss");
    public static final ConcurrentDateFormat DATE_FORMAT = ConcurrentDateFormat.of("yyyy-MM-dd");
    public static final ConcurrentDateFormat TIME_FORMAT = ConcurrentDateFormat.of("HH:mm:ss");
    public static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss");

    public static Date now() {
        return new Date();
    }

    /**
     * 字符串转时间
     *
     * @param dateStr 字符串
     * @param pattern 时间格式
     * @return
     * @throws ParseException
     */
    public static Date parse(String dateStr, String pattern) throws ParseException {
        ConcurrentDateFormat format = ConcurrentDateFormat.of(pattern);
        return format.parse(dateStr);
    }

    public static Date parse(String dateStr, ConcurrentDateFormat format) throws ParseException {
        return format.parse(dateStr);
    }


}
